package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.Coupons;
import com.ruoyi.common.core.Entity.Goods;
import com.ruoyi.common.core.Entity.Orders;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
@SuppressWarnings("all")
public interface OrdersDAO {


    List<Orders> findOrdersList(Orders orders);
    List<Orders> findOrdersListByNormalStore(@Param("orders") Orders orders, @Param("LoginUserId") long LoginUserId);

    List<Orders> findGoodsOrdersList(Orders orders);

    List<Orders> findGoodsOrdersListByNormalStore(@Param("orders") Orders orders, @Param("LoginUserId") long LoginUserId);

    List<Orders> findCouponsOrdersList(Orders orders);

    @Select("select count(0) from orders where del_flag = false")
    long findAllRecordForAdmin();

    @Select("select count(0) from orders where store_id = #{store_id} and del_flag = false")
    long findAllRecordForNormalStore(long store_id);

    @Insert("insert into orders values (#{order_id},#{order_user_id},#{store_id},#{goods_id},#{coupons_id},#{number},#{order_status},#{consignee_name}," +
            "#{consignee_phone},#{consignee_address},#{volunteer_area},#{deliver_type},#{order_time},#{deliver_time},#{del_flag})")
    void orderAdd(Orders orders);

    int updateOrder(Orders orders);

    @Select("select * from orders where order_id = #{order_id}")
    Orders findByOrder_id(long order_id);

    @Select("select count(0) from orders where date_format(order_time,'%Y-%m-%d') = #{today}")
    int New_order_number_today(String today);

    @Select("select * from orders where store_id = #{store_id} and date_format(order_time,'%Y-%m-%d') = #{today}")
    List<Orders> findOrdersByStoreIdandTime(@Param("store_id") long store_id,@Param("today") String today);

    @Select("select * from orders where store_id = #{store_id}")
    List<Orders> findOrdersByStoreId(long store_id);

    @Select("select distinct order_user_id from orders where store_id = #{store_id} and date_format(order_time,'%Y-%m-%d') = #{today}")
    List<Long> findPurchaseUserToday(@Param("store_id") long store_id,@Param("today") String today);

    @Select("select distinct order_user_id from orders where store_id = #{store_id}")
    List<Long> findPurchaseUserTotal(long store_id);

    @Select("select count(0) from orders where goods_id > 0 and del_flag = false")
    long findAllGoodsRecordNumber();

    @Select("select count(0) from orders where coupons_id > 0 and del_flag = false")
    long findAllCouponsRecordNumber();

    //查询某商店销量最高的商品
    List<Goods> findStoreBestSellingGoods(Long storeId);
    //查询所有商店中销量最高的3个商品
    List<Goods> findBestSellingGoods();
    //查询某商店最近售出的3个商品
    List<Goods> findStoreRecentlySoldGoods(Long storeId);
    //查询所有商店最近售出的3个商品
    List<Goods> findRecentlySoldGoods();
    //查询销量最高的3个优惠券
    List<Coupons> findBestSellingCoupons();
    //查询最近售出的3种优惠券
    List<Coupons> findRecentlySoldCoupons();

    Date findGoodsSoldTime(@Param("storeId") Long storeId,@Param("goodsId") Long goodsId);

    Date findCouponsSoldTime(Long couponId);

    long findGoodsTotalSold(@Param("storeId") Long storeId,@Param("goodsId") Long goodsId);
    long findCouponsTotalSold(@Param("couponsId") Long couponsId);

    List<Map<String, Object>> getVolunteerAreaData();


    List<Map<String, Object>> getStoreVolunteerAreaData(Long storeId);
}
